﻿using JNPF.Basics.Models;
using JNPF.Utils;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace JNPF.Basics.Logic
{
    /// <summary>
    /// 大数据测试
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2017.11.28 
    /// </summary>
    public class BigDataBll
    {
        private BigDataIService service = new BigDataService();

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="input">请求参数</param>
        /// <returns></returns>
        public async Task<PageResult<BigDataEntity>> GetList(PageInput input)
        {
            try
            {
                return await service.GetList(input);
            }
            catch (Exception ex)
            {
                throw ExceptionEx.Throw(ex);
            }
        }
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="insertCount">添加数量</param>
        public async Task Create(int insertCount)
        {
            try
            {
                var code = await service.MaxCode();
                var index = code == 0 ? 10000001 : code;
                if (index > 11500001)
                    throw new Exception("防止恶意创建过多数据。");
                List<BigDataEntity> entityList = new List<BigDataEntity>();
                for (int i = 0; i < insertCount; i++)
                {
                    entityList.Add(new BigDataEntity
                    {
                        Id = CommonHelper.Guid,
                        EnCode = index.ToString(),
                        FullName = "测试大数据" + index,
                        CreatorTime = DateTime.Now,
                    });
                    index++;
                }
                service.Create(entityList);
            }
            catch (Exception ex)
            {
                throw ExceptionEx.Throw(ex);
            }
        }
    }
}
